package com.duo.controller.user;


import com.duo.entity.Category;
import com.duo.result.BaseResult;
import com.duo.service.CategoryService;
import com.duo.vo.CategoryVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController("userCategoryController")
@RequestMapping("/user/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 分页查询套餐分类或菜品分类
     * @return
     */
    @GetMapping("/list")
    public Object select() {
        List<Category> list = categoryService.list();
        List<CategoryVO> categoryVOS = new ArrayList<>();
        list.forEach(category -> {
            CategoryVO categoryVO = new CategoryVO();
            BeanUtils.copyProperties(category, categoryVO);
            categoryVOS.add(categoryVO);
        });
        return BaseResult.success("类别分页查询成功", categoryVOS);
    }



}
